<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
		<meta charset="utf-8" />
<title>顶岗实习系统</title>
<meta name="author" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="css/style_2.css" />
<style>
body{height:100%;background:#16a085;overflow:hidden;}
canvas{z-index:-1;position:absolute;}
</style>
<body onload="createCode();">
<dl class="admin_login">
 <dt>
  <strong>顶岗实习管理系统(学生版)</strong>
  <em> Management of replacement internship System</em>
 </dt>
 <dd class="user_icon">
  <input type="text" placeholder="账号" class="login_txtbx" id="loginname"/>
 </dd>
 <dd class="pwd_icon">
  <input type="password" placeholder="密码" class="login_txtbx" id="password"/>
 </dd>
 <dd class="val_icon">
  <div class="checkcode">
    <input type="text" id="J_codetext" placeholder="验证码" maxlength="4" class="login_txtbx">
    <canvas class="J_codeimg" id="myCanvas" onclick="createCode()">对不起，您的浏览器不支持canvas，请下载最新版浏览器!</canvas>
  </div>
  <input type="button" value="验证码核验" class="ver_btn" onClick="validate();">
 </dd>
 
 <dd>
  <input type="button" value="立即登陆" class="submit_btn" onclick="severCheck();"/>
 </dd>
 <dd>
  <p>© 2016 合肥正鼎软件科技有限公司 版权所有</p>
 </dd>
</dl>
</body>
<script type="text/javascript" src="assets/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/jquery.tips.js"></script>
<script type="text/javascript" src="assets/js/jquery.cookie.js"></script>
<script src="js/verificationNumbers.js"></script>
<script type="text/javascript" src="layer/layer.js" ></script>
<script src="js/Particleground.js"></script>
<script>

  //验证码
  createCode();
  //测试提交，对接程序删除即可
  /* $(".submit_btn").click(function(){
	  location.href="main.html";
	}); */
jQuery(function() {
	var loginname = $.cookie('loginname');
	var password = $.cookie('password');
	var type = $.cookie('type');
	if (typeof(loginname) != "undefined"
			&& typeof(password) != "undefined") {
		$("#loginname").val(loginname);
		$("#password").val(password);
		$("#saveid").attr("checked", true);
		if(type==1){
			 $("input[name='type']:eq(1)").attr("checked","checked");
		}
	}
});
function severCheck(){
	 var inputCode = document.getElementById("J_codetext").value.toUpperCase();
	   var codeToUp=code.toUpperCase();
	    if(inputCode.length <=0) {
	    	$("#J_codetext").tips({
				side : 2,
				msg : '验证码不得为空',
				bg : '#AE81FF',
				time : 3
			});
	      createCode();
	      return false;
	    } else if(inputCode != codeToUp ){
	      document.getElementById("J_codetext").value="";
	      $("#J_codetext").tips({
				side : 2,
				msg : '验证码错误',
				bg : '#AE81FF',
				time : 3
			});
	      createCode();
	      return false;
	    } else { 
	if(check()){
		var loginname = $("#loginname").val();
		var password = $("#password").val();
		var role = loginname+",zt,"+password;
		$.ajax({
			type: "POST",
			url: 'student/login.do',
	    	data: {KEYDATA:role},
			dataType:'json',
			cache: false,
			success: function(data){
				if("success" == data.result){
					saveCookie();
					window.location.href="student/index.do";
				}else if("usererror" == data.result){
					$("#loginname").tips({
						side : 1,
						msg : "用户名或密码有误",
						bg : '#FF5080',
						time : 5
					});
					$("#loginname").focus();
				}  
			}
		});
	}  
}
	    }
//客户端校验
function check() {
	if ($("#loginname").val() == "") {
		$("#loginname").tips({
			side : 2,
			msg : '帐号不得为空',
			bg : '#AE81FF',
			time : 3
		});

		$("#loginname").focus();
		return false;
	} else {
		$("#loginname").val(jQuery.trim($('#loginname').val()));
	}

		if ($("#password").val() == "") {

			$("#password").tips({
				side : 2,
				msg : '密码不得为空',
				bg : '#AE81FF',
				time : 3
			});

			$("#password").focus();
			return false;
		}
		return true;
	}

	function savePaw() {
		if (!$("input[type='checkbox']").is(':checked')) {
			$.cookie('loginname', '', {
				expires : -1
			});
			$.cookie('password', '', {
				expires : -1
			});
			$("#loginname").val('');
			$("#password").val('');
		}
	}
	function saveCookie() {
		if ($("input[type='checkbox']").is(':checked')) {
			$.cookie('loginname', $("#loginname").val(), {
				expires : 7
			});
			$.cookie('password', $("#password").val(), {
			expires : 7
		});
		$.cookie('type', $("input[name='type']:checked").val(), {
			expires : 7
		});
	}
}
//TOCMAT重启之后 点击左侧列表跳转登录首页 
if (window != top) {
	top.location.href = location.href;
}
</script>
</html>

</script>
</html>
